# Beat self-config
# ================================ Logging ===================================
# repo: https://github.com/TencentBlueKing/beats
# path: libbeat/logp/config.go
logging:
  level: error
  rotateeverybytes: 10485760
  keepfiles: 7


# ================================ Output ====================================
# console for debugging
# output.console:

# bkpipe for production
output.bkpipe:
  endpoint: {{ plugin_path.endpoint }}
  synccfg: true


# ================================= Path =====================================
path:
  logs: {{ plugin_path.log_path }}
  data: {{ plugin_path.data_path }}
  pid: {{ plugin_path.pid_path }}


# ============================ Publisher Queue ===============================
# publisher 发送队列配置
# repo: https://github.com/TencentBlueKing/beats
# path: libbeat/publisher/queue/memqueue/config.go
queue:
  mem:
    events: 1024
    flush.min_events: 0
    flush.timeout: "1s"


# ============================== Monitoring ==================================
# 采集指标自监控上报
# repo: https://github.com/TencentBlueKing/collector-go-sdk.git
# path: bkbeat/bkmonitoring
xpack:
  monitoring:
    enabled: true
    # output 类型以及配置
    bkpipe:
      bk_biz_id: {{ plugin_monitoring.get("bk_biz_id", 2) if plugin_monitoring else 2 | int }}
      dataid: 1100006
      task_dataid: 1100007
      period: "30s"


# ================================= Resource =================================
resource_limit:
  disabled: true
#  # CPU 资源限制 单位 core(float64)
#  cpu: 1
#  # 内存资源限制 单位 MB(int)
#  mem: 512


# bk-collector self-config
bk-collector:
  # =============================== SubConfig ================================
  apm:
    patterns:
      - "{{ plugin_path.subconfig_path }}/bk-collector-*.conf"


  # =============================== Logging ==================================
  logging:
    # stdout: true
    # optional: logfmt/json/console
    format: "logfmt"
    level: error
    path: {{ plugin_path.log_path }}
    maxsize: 10
    maxage: 3
    backups: 5


  # =============================== Receiver =================================
  receiver:
    # Http Server Config
    http_server:
      # 是否启动 Http 服务
      # default: false
      enabled: true
      # 服务监听端点
      # default: ""
      endpoint: ":4318"
      middlewares:
        - "logging"
        - "cors"
        - "content_decompressor"

    # Grpc Server Config
    grpc_server:
      # 是否启动 Grpc 服务
      # default: false
      enabled: true
      # 传输协议，目前支持 tcp
      # default: ""
      transport: "tcp"
      # 服务监听端点
      # default: ""
      endpoint: ":4317"

  processor:
    # ApdexCalculator: 健康度状态计算器
    - name: "apdex_calculator/standard"
      config:
        calculator:
          type: "standard"
        rules:
          - kind: ""
            metric_name: "bk_apm_duration"
            destination: "apdex_type"
            apdex_t: 20 # ms

    # AttributeFilter: 属性过滤处理器
    - name: "attribute_filter/as_string"
      config:
        as_string:
          keys:
            - "attributes.db.name"

    # ResourceFilter: 资源过滤处理器
    - name: "resource_filter/instance_id"
      config:
        assemble:
          - destination: "bk.instance.id"
            separator: ":"
            keys:
              - "resource.telemetry.sdk.language"
              - "resource.service.name"
              - "resource.net.host.name"
              - "resource.net.host.ip"
              - "resource.net.host.port"
        drop:
          keys:
            - "bk.data.token"

    # Sampler: 采样处理器
    - name: "sampler/random"
      config:
        type: "random"
        sampling_percentage: 100

    # TokenChecker: 权限校验处理器
    - name: "token_checker/aes256"

    # TracesDeriver: Traces 派生处理器
    - name: "traces_deriver/duration"
      config:
        operations:
          - type: "duration"
            metric_name: "bk_apm_duration"
            rules:
              - kind: "SPAN_KIND_SERVER"
                predicate_key: ""
                dimensions:
                  - "resource.bk.instance.id"
                  - "span_name"
                  - "kind"
                  - "status.code"
                  - "resource.service.name"
                  - "resource.service.version"
                  - "resource.telemetry.sdk.name"
                  - "resource.telemetry.sdk.version"
                  - "resource.telemetry.sdk.language"
                  - "attributes.peer.service"
              - kind: "SPAN_KIND_SERVER"
                predicate_key: "attributes.http.method"
                dimensions:
                  - "resource.bk.instance.id"
                  - "span_name"
                  - "kind"
                  - "status.code"
                  - "resource.service.name"
                  - "resource.service.version"
                  - "resource.telemetry.sdk.name"
                  - "resource.telemetry.sdk.version"
                  - "resource.telemetry.sdk.language"
                  - "attributes.peer.service"
                  - "attributes.http.server_name"
                  - "attributes.http.client_ip"
                  - "attributes.net.host.name"
                  - "attributes.net.host.ip"
                  - "attributes.net.host.port"
                  - "attributes.http.method"
                  - "attributes.http.route"
                  - "attributes.http.scheme"
                  - "attributes.http.flavor"
                  - "attributes.http.response_content_length"
                  - "attributes.http.status_code"
              - kind: "SPAN_KIND_SERVER"
                predicate_key: "attributes.rpc.system"
                dimensions:
                  - "resource.bk.instance.id"
                  - "span_name"
                  - "kind"
                  - "status.code"
                  - "resource.service.name"
                  - "resource.service.version"
                  - "resource.telemetry.sdk.name"
                  - "resource.telemetry.sdk.version"
                  - "resource.telemetry.sdk.language"
                  - "attributes.peer.service"
                  - "attributes.net.host.name"
                  - "attributes.net.host.ip"
                  - "attributes.net.host.port"
                  - "attributes.rpc.method"
                  - "attributes.rpc.service"
                  - "attributes.rpc.system"
                  - "attributes.rpc.grpc.status_code"
              - kind: "SPAN_KIND_CLIENT"
                predicate_key: ""
                dimensions:
                  - "resource.bk.instance.id"
                  - "span_name"
                  - "kind"
                  - "status.code"
                  - "resource.service.name"
                  - "resource.service.version"
                  - "resource.telemetry.sdk.name"
                  - "resource.telemetry.sdk.version"
                  - "resource.telemetry.sdk.language"
                  - "attributes.peer.service"
              - kind: "SPAN_KIND_CLIENT"
                predicate_key: "attributes.http.method"
                dimensions:
                  - "resource.bk.instance.id"
                  - "span_name"
                  - "kind"
                  - "status.code"
                  - "resource.service.name"
                  - "resource.service.version"
                  - "resource.telemetry.sdk.name"
                  - "resource.telemetry.sdk.version"
                  - "resource.telemetry.sdk.language"
                  - "attributes.peer.service"
                  - "attributes.http.method"
                  - "attributes.http.status_code"
                  - "attributes.net.peer.name"
                  - "attributes.net.peer.ip"
                  - "attributes.net.peer.port"
              - kind: "SPAN_KIND_CLIENT"
                predicate_key: "attributes.rpc.system"
                dimensions:
                  - "resource.bk.instance.id"
                  - "span_name"
                  - "kind"
                  - "status.code"
                  - "resource.service.name"
                  - "resource.service.version"
                  - "resource.telemetry.sdk.name"
                  - "resource.telemetry.sdk.version"
                  - "resource.telemetry.sdk.language"
                  - "attributes.peer.service"
                  - "attributes.rpc.method"
                  - "attributes.rpc.service"
                  - "attributes.rpc.system"
                  - "attributes.rpc.grpc.status_code"
                  - "attributes.net.peer.name"
                  - "attributes.net.peer.ip"
                  - "attributes.net.peer.port"
              - kind: "SPAN_KIND_CLIENT"
                predicate_key: "attributes.db.system"
                dimensions:
                  - "resource.bk.instance.id"
                  - "span_name"
                  - "kind"
                  - "status.code"
                  - "resource.service.name"
                  - "resource.service.version"
                  - "resource.telemetry.sdk.name"
                  - "resource.telemetry.sdk.version"
                  - "resource.telemetry.sdk.language"
                  - "attributes.peer.service"
                  - "attributes.db.name"
                  - "attributes.db.operation"
                  - "attributes.db.system"
                  - "attributes.net.peer.name"
                  - "attributes.net.peer.ip"
                  - "attributes.net.peer.port"
              - kind: "SPAN_KIND_PRODUCER"
                predicate_key: ""
                dimensions:
                  - "resource.bk.instance.id"
                  - "span_name"
                  - "kind"
                  - "status.code"
                  - "resource.service.name"
                  - "resource.service.version"
                  - "resource.telemetry.sdk.name"
                  - "resource.telemetry.sdk.version"
                  - "resource.telemetry.sdk.language"
                  - "attributes.peer.service"
              - kind: "SPAN_KIND_PRODUCER"
                predicate_key: "attributes.messaging.system"
                dimensions:
                  - "resource.bk.instance.id"
                  - "span_name"
                  - "kind"
                  - "status.code"
                  - "resource.service.name"
                  - "resource.service.version"
                  - "resource.telemetry.sdk.name"
                  - "resource.telemetry.sdk.version"
                  - "resource.telemetry.sdk.language"
                  - "attributes.peer.service"
                  - "attributes.messaging.system"
                  - "attributes.messaging.destination"
                  - "attributes.messaging.destination_kind"
                  - "attributes.net.peer.name"
                  - "attributes.net.peer.ip"
                  - "attributes.net.peer.port"
                  - "attributes.celery.action"
                  - "attributes.celery.task_name"
              - kind: "SPAN_KIND_CONSUMER"
                predicate_key: ""
                dimensions:
                  - "resource.bk.instance.id"
                  - "span_name"
                  - "kind"
                  - "status.code"
                  - "resource.service.name"
                  - "resource.service.version"
                  - "resource.telemetry.sdk.name"
                  - "resource.telemetry.sdk.version"
                  - "resource.telemetry.sdk.language"
                  - "attributes.peer.service"
              - kind: "SPAN_KIND_CONSUMER"
                predicate_key: "attributes.messaging.system"
                dimensions:
                  - "resource.bk.instance.id"
                  - "span_name"
                  - "kind"
                  - "status.code"
                  - "resource.service.name"
                  - "resource.service.version"
                  - "resource.telemetry.sdk.name"
                  - "resource.telemetry.sdk.version"
                  - "resource.telemetry.sdk.language"
                  - "attributes.peer.service"
                  - "attributes.net.host.name"
                  - "attributes.net.host.ip"
                  - "attributes.net.host.port"
                  - "attributes.messaging.system"
                  - "attributes.celery.state"
                  - "attributes.celery.action"

  pipeline:
    - name: "traces_pipeline/common"
      type: "traces"
      processors:
        - "token_checker/aes256"
        - "resource_filter/instance_id"
        - "attribute_filter/as_string"
        - "traces_deriver/duration"
        - "sampler/random"

    - name: "metrics_pipeline/derived"
      type: "metrics.derived"
      processors:
        - "apdex_calculator/standard"

  # =============================== Exporter =================================
  exporter:
    queue:
      batch_size: 100  # default: 1
      flush_interval: 1s
